<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebSocket Test</title>
</head>
<body>
    <h1>Hello World</h1>
    <script>
        const socket = new WebSocket("ws://localhost:8080/ws?websocketID=123");

        // 连接建立时触发
        socket.addEventListener("open", (event) => {
            console.log("WebSocket connection opened:", event);
        });

        // 收到消息时触发
        socket.addEventListener("message", (event) => {
            console.log("Received message:", event.data);
        });

        // 连接关闭时触发
        socket.addEventListener("close", (event) => {
            console.log("WebSocket connection closed:", event);
        });

        // 发送消息示例
        setTimeout(() => {
            socket.send("Hello, WebSocket!");
        }, 2000);
    </script>
</body>
</html>
